﻿/**
*房源添加页类
*/
Chenxin.UI.HouseBaseInfoAdd=Chenxin.extend(Chenxin.UI.PageCommon,{
    actionUrl: 'service/HouseMgr.ashx',
	initEvent:function(){
		var _this=this;
		$('.a-continue').click(function(){
			if(this.name=='same'){
				_this.form.fitCommunityInfo();
			}else{
				_this.form.building.clearItems();
			}
			$('#addsucc_msg').jqmHide();
		});
	
	},
	createForm:function(){
		return new Chenxin.UI.HouseBaseInfoAddForm({
			type:'numal'
		});
	},
	initComponent:function(){
		Chenxin.UI.HouseBaseInfoAdd.superclass.initComponent.call(this);
	}	
});

Chenxin.UI.HouseBaseInfoAddForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/HouseMgr.ashx',
    type: 'numal',
    id: 'housebaseinfo_form',
    protectBy: '',
    ppcVal: {},
    showProtectPhone: function(type, value) {
        if (value) {
            value += '';
        }
        if (value == '请选择') {
            return;
        }

        if (!this.ppcVal[type]) {//没有判断过，插入
            this.ppcVal[type] = value;
            if (this.isProtectPhone) {//已经是保护，无需判断
                return;
            } else {//不是保护状态，判断并保护
                for (var i = 0; i < this.ppConfig.length; i++) {
                    var tc = this.ppConfig[i];
                    if (tc.ConfigType == type && tc.ConfigMinValue <= value && tc.ConfigMaxValue >= value) {
                        this.isProtectPhone = true;
                    }
                }
            }
        } else {//已经判断过
            if (this.ppcVal[type] == value) {
                return;
            }

            this.ppcVal[type] = value;
            var e = false;
            for (var t in this.ppcVal) {//循环判断队列
                for (var i = 0; i < this.ppConfig.length; i++) {//循环配置队列
                    var tc = this.ppConfig[i];
                    if (tc.ConfigType == t && tc.ConfigMinValue <= this.ppcVal[t] && tc.ConfigMaxValue >= this.ppcVal[t]) {
                        e = true;
                        break;
                    }
                }
                if (e) {
                    break;
                }
            }
            this.isProtectPhone = e;
        }
        if (this.isProtectPhone) {
            $('.protectPhone').show();
        } else {
            $('.protectPhone').hide();
        }
    },
    getPPCList: function() {
        var _this = this;
        Chenxin.ajax({
            url: '/service/ProtectedPhoneConfigMgr.ashx?op=getppclist',
            data: {},
            onSuccess: function(data, msg) {
                _this.ppConfig = data.ppc;
            }
        });
    },
    afterGetFormJson: function(model) {
        if (model.IsGroup == 'true') {
            model.IsGroup = true;
        } else {
            model.IsGroup = false;
        }
        if (this.currentCommunityInfo) {
            model.CommunityId = this.currentCommunityInfo.CommunityId;
            model.Address = this.currentCommunityInfo.Address;
            model.Block = this.currentCommunityInfo.Block;
            model.Region = this.currentCommunityInfo.Region;
        }

        customerModel = {};
        if (model.Mobile) {
            customerModel.Mobile = model.Mobile;
            delete model.Mobile;
        }
        if (model.Phone) {
            customerModel.Phone = model.Phone;
            delete model.Phone;
        }
        customerModel.CustomerName = model.CustomerName;
        if (model.BusinessKind == '10') {
            delete model.IsGroup;
        }
        if (model.IsProtectHouse == undefined) {
            model.IsProtectHouse = false;
        }

        model.BuildingArea = Chenxin.Fn.fullToHalfChar(model.BuildingArea);
        model.IsAutoProPhone = this.isProtectPhone;
        if (model.IsAutoProPhone == undefined) {
            model.IsAutoProPhone = false;
        }

        if (model.IsAutoProPhone) {
            model.IsProtectPhone = true;
        }

        var houseid = Chenxin.Fn.getQueryString("houseid")
        if (houseid != null && houseid != "") {
            this.additionalParam.houseid = houseid;
        }
        this.additionalParam.customermodel = customerModel.toString();
    },
    formValidator: function(model) {
        var msg = '';
        switch (model.BusinessKind) {
            case '10': //出售，无需填写出租价格
                if (!model.SalePrice_T) {
                    msg = '请填写出售总价！';
                }
                break;
            case '20': //出租，无需填写出售价格
                if (!model.RentPrice) {
                    msg = '请填写出租价格！';
                }
                break;
            case '30': //出售和出租价格都需要填写			
                if (!model.SalePrice_T) {
                    msg = '出售总价';
                }
                if (!model.RentPrice) {
                    if (msg) {
                        msg += '和出租价格';
                    } else {
                        msg = '出租价格'
                    }
                }
                if (msg) {
                    msg = '请填写' + msg + '!';
                }
                break;
        }
        if (msg) {
            alert(msg);
            return false;
        }
        return Chenxin.UI.HouseBaseInfoForm.superclass.formValidator.call(this, model);
    },
    saveSucc: function(data, msg) {
        $('#span_housecode').text(data.HouseCode);
        $('#addsucc_msg').jqmShow();
    },
    customerFormVal: function(model) {
        eval("var json=" + this.additionalParam.customermodel)
        if (!json.Mobile && !json.Phone) {
            alert('客户手机和电话至少填写一项！');
            return false;
        }
		if($('#erromsg').text()){
			alert('房源已经存在，不能添加！');
			return false;
		}
		if(model.Total_Floor){
			if(parseInt(model.Cur_Floor)>parseInt(model.Total_Floor)){
				alert('层高不能大于总层数');
				return false;
			}
		}
        return true;
    },
    initFormValidator: function() {
        var _this = this;
        //小区非空验证
        $("#txtCommunity").formValidator({
            validatorgroup: this.id,
            onshow: "请输入小区名称！",
            onfocus: "中文或拼音",
            oncorrect: " "
        }).inputValidator({ //非空验证
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "小区名称不能为空!"
            },
            onerror: "小区名称不能为空!"
        });

        //房间号非空验证
        $("#txtRoom").formValidator({
            validatorgroup: this.id,
            onshow: "请输入房间号！",
            onfocus: "请输入房间号",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if (val.indexOf('0') == 0) {//判断是否以0开头
                    return '不能以0开头';
                }

                if (_this.currentBuildingModel) {
                    if (_this.currentBuildingModel.RoomRule == '*' || _this.currentBuildingModel.RoomRule == '') {//独栋别墅,任意房间号
                        //进行AJAX验证-
                        var _data = { exist: true };
                        Chenxin.ajax({
                            type: "get",
                            dataType: "json",
                            async: false,
                            url: _this.actionUrl,
                            data: { op: 'checkroom', room: val, communityid: _this.currentCommunityInfo.CommunityId, buildingid: _this.currentBuildingModel.BuildingId },
                            onSuccess: function(data) {
                                _data = data;
                            }
                        });
                        if (_data.exist) {
							$('#erromsg').text('房间号已经存在！房源编号：[<a href="ShowDetailInfo.aspx?houseid=' + _data.model.HouseId + '" target="_blank">' + _data.model.HouseCode + '</a>] 交易类型：' + _data.model.BusinessKind);
                            return false;
                        } else {
							$('#erromsg').text('');
                            return true;
                        }
                    } else {
                        eval('s=/' + _this.currentBuildingModel.RoomRule + '/');
                        if (s.test(val)) {//进行AJAX验证
                            var data = { exist: true };
                            Chenxin.ajax({
                                type: "get",
                                dataType: "json",
                                async: false,
                                url: _this.actionUrl,
                                data: { op: 'checkroom', room: val, communityid: _this.currentCommunityInfo.CommunityId, buildingid: _this.currentBuildingModel.BuildingId },
                                onSuccess: function(data) {
                                    _data = data;
                                }
                            });
                            if (_data.exist) {
                                var msg = '房源已经存！编号：[<a href="ShowDetailInfo.aspx?houseid=' + _data.model.HouseId + '" target="_blank">' + _data.model.HouseCode + '</a>] 交易类型：[';
                                switch (_data.model.BusinessKind) {
                                    case 10:
                                        msg += '出售';
                                        break;
                                    case 20:
                                        msg += '出租';
                                        break;
                                    case 30:
                                        msg += '租售';
                                        break;
                                }
                                msg += '] 状态：[';
								switch(_data.model.Status){
									case 10:
										msg += '有效';
										break;
									case -1:
										msg += '无效';
										break;
									case 20:
										msg += '暂缓';
										break;
									case 30:
										msg += '封盘';
										break;
									case -10:
										msg += '删除';
										break;
									default:
										msg += '错误';
										break;
								}
                                msg += ']'
                                return msg;
                            } else {
                                return true;
                            }
                        } else {
                            return false;
                        }
                    }
                }
                return '请先选择楼栋！';
            },
            onerror: '房间号格式错误！'
        });

        //面积验证
        $("#txtBuildingArea").formValidator({
            validatorgroup: this.id,
            onshow: "请输入房源面积！",
            onfocus: "请输入房源面积",
            oncorrect: " "
        }).inputValidator({ //非空验证
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "面积不能为空!"
            },
            onerror: "面积不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                val = Chenxin.Fn.fullToHalfChar(val);
                if (parseInt(val) <= 0 || parseInt(val) > 10000000) {
                    return false;
                }
                else {
                    return val.isNum();
                }
            },
            onerror: "请输入非0正数"
        });

        //客户姓名非空验证
        $("#txtCustomerName").formValidator({
            validatorgroup: this.id,
            onshow: "请输入客户姓名！",
            onfocus: "请输入客户姓名",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "客户姓名不能为空!"
            },
            onerror: "客户姓名不能为空!"
        });

		
		$("#txtModel_Room").formValidator({
            validatorgroup: this.id,
            onshow: "",
            onfocus: "请输入数字",
            oncorrect: ""
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "室不能为空!"
            },
            onerror: "室不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                return val.isNum();
            }, onerror: "请输入数字"
        });
		
		$("#txtModel_Hall").formValidator({
            validatorgroup: this.id,
            onshow: "",
            onfocus: "请输入数字",
            oncorrect: ""
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "厅不能为空!"
            },
            onerror: "厅不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                return val.isNum();
            }, onerror: "请输入数字"
        });
		
		$("#txtModel_Toilet").formValidator({
            validatorgroup: this.id,
            onshow: "",
            onfocus: "请输入数字",
            oncorrect: ""
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "卫不能为空!"
            },
            onerror: "卫不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                return val.isNum();
            }, onerror: "请输入数字"
        });
		
		$("#txtCur_Floor").formValidator({
            validatorgroup: this.id,
            onshow: "",
            onfocus: "请输入数字",
            oncorrect: ""
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "楼层不能为空!"
            },
            onerror: "楼层不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                return val.isNum();
            }, onerror: "请输入数字"
        });
		$("#txtTotal_Floor").formValidator({
            validatorgroup: this.id,
            onshow: "",
            onfocus: "请输入数字",
            oncorrect: ""
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "总楼层不能为空!"
            },
            onerror: "总楼层不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                return val.isNum();
            }, onerror: "请输入数字"
        });
		
        //手机号码验证
        $("#txtMobile").formValidator({
            validatorgroup: this.id,
            onshow: "请输入手机或者电话",
            onfocus: "请输入手机或者电话。",
            oncorrect: " ", onerror: ""
        }).functionValidator({
            fun: function(val, elem) {
				if(val.isBlank()||val.isMobile()){
					return true;
				}
				return "请输入正确的手机号";                
            }
        });
        /*
        //电话
        $("#txtPhone").formValidator({
        validatorgroup: this.id,
        onshow: "请输入电话",
        onfocus: "请输入电话",
        oncorrect: " ", onerror: ""
        }).functionValidator({
        fun: function(val, elem) {
        if (!$("#txtPhone").val().isBlank()) {
        if (!$("#txtPhone").val().isTel()) {
        return "请输入正确的电话,规则:国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)";
        }
        }
        return true;
        }
        });*/

        //价格验证
        /**/
        $("#txtSalePrice_T").formValidator({
            validatorgroup: this.id,
            onshow: "请输入出售总价(元)",
            onfocus: "请输入出售总价(元)",
            oncorrect: " "
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                if (parseInt(val) > 10000000000 || parseInt(val) < 0) {
                    return '请输入小于10,000,000,000大于0的数字';
                }
                if (!$("#txtSalePrice_R").val().isBlank()) {
                    if (parseInt($("#txtSalePrice_R").val()) > parseInt(val)) {
                        $.formValidator.setTipState(document.getElementById("txtSalePrice_R"), "onError", "底价不能大于总价");
                    }
                }

                return val.isNum();
            }, onerror: "请输入数字"
        });

        $("#txtSalePrice_R").formValidator({
            validatorgroup: this.id,
            onshow: " ",
            onfocus: " ",
            oncorrect: " "
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                if (parseInt(val) > 10000000000 || parseInt(val) < 0) {
                    return '请输入小于10,000,000,000大于0的数字';
                }
                if (!val.isBlank()) {
                    if (parseInt($("#txtSalePrice_T").val()) < parseInt(val))
                        return false;
                }

                return true;
            }, onerror: "底价不能大于总价"
        });

        $("#txtRentPrice").formValidator({
            validatorgroup: this.id,
            onshow: "请输入出租价格(元)",
            onfocus: "请输入出租价格(元)",
            oncorrect: " "
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                if (parseInt(val) > 10000000000 || parseInt(val) < 0) {
                    return '请输入小于10,000,000,000大于0的数字';
                }
                if (!$("#txtRentPrice_R").val().isBlank()) {
                    if (parseInt($("#txtRentPrice_R").val()) > parseInt(val)) {
                        $.formValidator.setTipState(document.getElementById("txtRentPrice_R"), "onError", "底价不能大于总价");
                    }
                }

                return val.isNum();
            }, onerror: "请输入数字"
        });

        $("#txtRentPrice_R").formValidator({
            validatorgroup: this.id,
            onshow: " ", onfocus: " ", oncorrect: " "
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                if (parseInt(val) > 10000000000 || parseInt(val) < 0) {
                    return '请输入小于10,000,000,000大于0的数字';
                }
                if (!val.isBlank()) {
                    if (parseInt($("#txtRentPrice").val()) < parseInt(val))
                        return false;
                }

                return true;
            }, onerror: "底价不能大于总价"
        });

        //保护电话
        $("#txtDisplayPhone").formValidator({
            validatorgroup: this.id,
            onshow: "请输入保护电话！", onfocus: "请输入保护电话", oncorrect: " "
        }).functionValidator({ //手机号验证
            fun: function(val, elem) {
                if (!_this.isProtectPhone) {//如果不需要填写，不验证
                    return true;
                }
                // return (val.isMobile() || val.isTel());
                if (val.length > 50 || val.length == 0) {
                    return false;
                }
                return true;
            },
            onerror: "请输入正确的电话"
        });
    },
    createComboList: function() {
        var _this = this;
        var year = new Date().getFullYear();
        var yearItems = [];
        for (var i = year - 30; i <= year; i++) {
            yearItems.push({ txt: i, val: i });
        }

        this.region = new Chenxin.UI.ParameterCombo({
            name: 'Region',
            containerId: '#house_region',
            key: 'System.Region',
            tbxWidth: 120,
            inModelType: 'txt',
            afterSetValue: function(newVal) {
                if (newVal == this.defVal) {
                    _this.block.clearItems();
                    area.clearItems();
                } else {
                    _this.block.param.subkey = newVal;
					_this.block.param.recordid=this.getValueRecord()['id'];
                    _this.block.reload(_this.currentCommunityInfo.Block);
                    area.param.subkey = newVal;
					area.param.recordid=this.getValueRecord()['id'];
                    area.reload(_this.currentCommunityInfo.CommunityBlock);
                }
            },
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    _this.block.clearItems();
                    area.clearItems();
                } else {
                    _this.block.param.subkey = this.getValue();
                    _this.block.reload();					
					
                    area.param.subkey = this.getValue();
                    area.reload();
                }
            }
        });
        this.block = new Chenxin.UI.ParameterCombo({
            containerId: '#house_block',
            name: 'Block',
            key: 'System.Block',
            tbxWidth: 120,
            colWidth: 90,
            inModelType: 'txt',
            autoLoad: false
        });
		
		var area=new Chenxin.UI.ParameterCombo({
			name:'HouseBlock',
			containerId: '#house_area',
			key:'System.Area',
            tbxWidth: 120,
            colWidth: 90,
			inModelType:'txt',
			autoLoad:false
		});

        //楼栋
        this.building = new Chenxin.UI.Combo({
            actionUrl: 'service/CommunityBuildingMgr.ashx?op=getcombolist',
            containerId: '#house_building',
            typeModel: 'new',
            name: 'BuildingId',
            inModelType: 'all',
			hasSearch:true,
            tbxWidth: 120,
            colNum: 6,
            txtModelName: 'BuildingName',
            autoLoad: false,
            hasPage: true,
			pageSize:60,
            onSelected: function() {
                _this.loadBuildingInfo(this.getValue());
            }
        });

        //房屋类型
        var buildingType = new Chenxin.UI.ParameterCombo({
            containerId: '#house_BuildingType',
            name: 'BuildingType',
            key: 'Building.Type',
            inModelType: 'txt',
            autoLoad: true,
            tbxWidth: 120,
            required: true,
            afterSetValue: function(newVal, oldVal) {
                _this.showProtectPhone.call(_this, this.key, this.getValue());
            },
            onSelected: function() {
                _this.showProtectPhone.call(_this, this.key, this.getValue());
            }
        });
        //房屋用途
        this.houseUse = new Chenxin.UI.ParameterCombo({
            containerId: '#house_CommunityUse',
            name: 'HouseUse',
            key: 'House.Use',
            inModelType: 'txt',
            tbxWidth: 120,
            required: true,
            afterSetValue: function(newVal, oldVal) {
                _this.showProtectPhone.call(_this, this.key, this.getValue());
            },
            onSelected: function() {
                _this.showProtectPhone.call(_this, this.key, this.getValue());
            }
        });
        //朝向
        var houseToward = new Chenxin.UI.ParameterCombo({
            containerId: '#house_Direction',
            name: 'Direction',
            key: 'System.Toward',
            inModelType: 'txt',
            tbxWidth: 120
        });
        //产权情况
        var houseProperty = new Chenxin.UI.ParameterCombo({
            containerId: '#house_Property',
            name: 'Property',
            key: 'House.Property',
            inModelType: 'txt',
            tbxWidth: 120
        });
        //信息来源
        var houseSource = new Chenxin.UI.ParameterCombo({
            containerId: '#house_InfoSource',
            name: 'InfoSource',
            key: 'House.Source',
            inModelType: 'txt',
            tbxWidth: 120
        });
        //支付方式
        var housePaymode = new Chenxin.UI.ParameterCombo({
            containerId: '#house_PayMode',
            name: 'PayMode',
            key: 'House.Paymode',
            inModelType: 'txt',
            tbxWidth: 120
        });
        //房源现状
        var houseActuality = new Chenxin.UI.ParameterCombo({
            containerId: '#house_Actuality',
            name: 'Actuality',
            key: 'House.Actuality',
            inModelType: 'txt',
            tbxWidth: 120,
            required: true
        });
        //装修程度
        var fitment = new Chenxin.UI.ParameterCombo({
            containerId: '#house_Fitment',
            name: 'Fitment',
            key: 'House.Fitment',
            inModelType: 'txt',
            tbxWidth: 120
        });
        //建筑年限
        var completeYear = new Chenxin.UI.BuildingYearCombo({
            containerId: '#house_CompleteYear',
            tbxWidth: 120
        });

        return [buildingType, this.region, this.block,area, this.houseUse, houseToward, houseProperty, houseSource, housePaymode, houseActuality, fitment, this.building, completeYear];
    },
    loadBuildingInfo: function(modelId, noResetRoom) {
        if (modelId == '请选择') {
            $('#span_RoomRuleRemark').remove();
            this.findByName('Room').val('');
            if (this.currentBuildingModel) {
                delete this.currentBuildingModel
            }
            return;
        }
        var _this = this;
        Chenxin.ajax({
            type: "post",
            dataType: "json",
            url: 'service/CommunityBuildingMgr.ashx',
            data: { op: 'getinfo', modelid: modelId,},
            onSuccess: function(data) {
				if(data.exist){
					var msg='房间号已经存在！房源编号：[<a href="ShowDetailInfo.aspx?houseid=' + data.housemodel.HouseId + '" target="_blank">' + data.housemodel.HouseCode + '</a>] 交易类型：';
					switch (data.housemodel.BusinessKind) {
						case 10:
							msg += '出售';
							break;
						case 20:
							msg += '出租';
							break;
						case 30:
							msg += '租售';
							break;
					}
					$('#erromsg').html(msg);
				}else{
					$('#erromsg').text('');				
				}
                _this.currentBuildingModel = data.model;
                if ($('#span_RoomRuleRemark').length) {
                    $('#span_RoomRuleRemark').text(data.model.RoomRuleRemark);
                } else {
                    $('#tr_roomnumber').after('<tr><th></th><td><span id="span_RoomRuleRemark" style="color:#ff0000;">' + data.model.RoomRuleRemark + '</span></td></tr>');
                }
                if (!noResetRoom) {
                    _this.findByName('Room').val('');
                }
                if (data.model.RoomRule == '*' || data.model.RoomRule == '') {//独栋别墅，无需填写房间号
                    $('.tr_roomnumber').hide();
					$("#txtRoom").unFormValidator(true);
                } else {
                    $('.tr_roomnumber').show();
					$("#txtRoom").unFormValidator(false);
                }

                if (_this.currentBuildingModel.Floor == null) {
                    _this.currentBuildingModel.Floor = '';
                }
                $('#txtTotal_Floor').val(_this.currentBuildingModel.Floor);
            }
        });
    },
    fitCommunityInfo: function() {
        var _data = {};
        _data.CompleteYear = this.currentCommunityInfo.CompleteYear;
        _data.BuildingType = this.currentCommunityInfo.BuildingType;
        _data.Community = this.currentCommunityInfo.CommunityName;
        _data.HouseUse = this.currentCommunityInfo.CommunityUse;
        _data.Region = this.currentCommunityInfo.Region;
        _data.Address = this.currentCommunityInfo.Address;
        //this.block.initValue=this.currentCommunityInfo.Block;
        this.fitData(_data, true);
    },
	
				
	checkNeedArea:function(companyid){
		var _this=this;
		Chenxin.ajax({				
			type: "get",
			dataType: "json",
			url: '/service/communitymgr.ashx?op=checkneedarea',
			data: {companyid:companyid},
			onSuccess: function(data,msg) {
				_this.findByName('HouseBlock').required=data.needArea;
				$('.tr_housearea')[data.needArea?'show':'hide']();
			}
		});
	},
    initEvent: function() {
        var _this = this;
        $('#btnSearchNews').live('click', function() {
            var buildingId = _this.findByName('BuildingId');

            if (buildingId.getValue() == buildingId.defVal) {
                alert('请选择楼栋！');
                return;
            }
            var msg = '';
            msg += _this.findByName('Community').val() + '小区';
            msg += buildingId.getText();
            msg += _this.findByName('Room').val() + '房间';
            msg += '是否需要保存?';

            if (confirm(msg)) {
                _this.save();
            }

        });

        //小区自动填充
        $('#txtCommunity').autocomplete({
            deferRequestBy: 5,
			width:200,
            serviceUrl: this.actionUrl + '?op=loadcommunity',
            onSelect: function(value, data) {
                _this.currentCommunityInfo = data;
                _this.fitCommunityInfo();
                _this.building.param.CommunityId = _this.currentCommunityInfo.CommunityId;
                _this.building.reload();
				_this.checkNeedArea(data.CompanyId);
            }
        });
		
		$('#txtCommunity').change(function(){
			if(_this.currentCommunityInfo){
				if(_this.currentCommunityInfo.CommunityName!=this.value){
					this.value=_this.currentCommunityInfo.CommunityName;
				}
			}
		});
		
        this.findByName('BusinessKind').bind('click', function() {
            switch (this.value) {
                case '10': //出售
                    $('.tr_rentprice').hide();
                    $('.tr_saleprice').show();
                    break;
                case '20': //出租
                    $('.tr_rentprice').show();
                    $('.tr_saleprice').hide();
                    break;
                default: //租售
                    $('.tr_rentprice').show();
                    $('.tr_saleprice').show();
                    break;
            }
        });

        $('.checkEquip').click(function() {
            var _val = $('#BaseEquip').val();
            if (this.checked) {
                $('#BaseEquip').val(_val + this.value + ',');
            } else {
                $('#BaseEquip').val(_val.replace(this.value + ',', ''));
            }
        });
    },
	initComponent: function() {
        Chenxin.UI.HouseBaseInfoAddForm.superclass.initComponent.call(this);
        this.getPPCList();
    }
});


$(document).ready(function() {
    var houseBaseInfoAdd = new Chenxin.UI.HouseBaseInfoAdd();
    var id = Chenxin.Fn.getQueryString("id");
    var houseid = Chenxin.Fn.getQueryString("houseid")

    if ((id != null && id != "") || (houseid != null && houseid != "")) {
        Chenxin.ajax({
            type: "post",
            dataType: "json",
            url: 'service/publicHouse.ashx',
            data: { op: 'getcommunityinfo', modelid: id, houseid: houseid },
            onSuccess: function(data, msg) {

                if (data.comminity) {
                    houseBaseInfoAdd.form.currentCommunityInfo = data.comminity;
                    houseBaseInfoAdd.form.fitCommunityInfo();
                }
                if (data.house) {
                    $("#txtRoom").val(data.house.Room);
                    $("#txtCustomerName").val(data.house.CustomerName);
                    $("#txtMobile").val(data.house.Mobile);
                    $("#txtPhone").val(data.house.Phone);
                    $("#txtBuildingArea").val(data.house.BuildingArea);
                    if (data.comminity) {
                        houseBaseInfoAdd.form.building.param.CommunityId = houseBaseInfoAdd.form.currentCommunityInfo.CommunityId;
                        houseBaseInfoAdd.form.building.reload(data.house.BuildingId);
                        houseBaseInfoAdd.form.loadBuildingInfo(data.house.BuildingId,true);
                    }

                }
            }
        });
    }
    $('#addsucc_msg').jqm({ trigger: false }).jqDrag('.jqDrag');
});

